package com.songlanyun.modules.areafeature.controller.admin;

import java.util.Arrays;
import java.util.Map;

import com.songlanyun.modules.areafeature.model.GoodsAreaFeatureDTO;
import com.songlanyun.modules.user.controller.AbstractController;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import com.songlanyun.modules.areafeature.entity.GoodsAreaFeatureEntity;
import com.songlanyun.modules.areafeature.service.GoodsAreaFeatureService;
import com.songlanyun.common.utils.PageUtils;
import com.songlanyun.common.utils.R;



/**
 * 商品特征分区
 *
 * @author lubo
 * @email sunlightcs@gmail.com
 * @date 2022-07-23 10:23:51
 */
@RestController
@RequestMapping("admin/goodsareafeature")
public class GoodsAreaFeatureController extends AbstractController {
    @Autowired
    private GoodsAreaFeatureService goodsAreaFeatureService;

    /**
     * 列表
     */
    @RequestMapping("/page")
    //@RequiresPermissions("areafeature:goodsareafeature:list")
    public R page(@RequestParam Map<String, Object> params){
        PageUtils page = goodsAreaFeatureService.queryPage(params);
        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    //@RequiresPermissions("areafeature:goodsareafeature:info")
    public R info(@PathVariable("id") Long id){
		GoodsAreaFeatureEntity goodsAreaFeature = goodsAreaFeatureService.getById(id);

        return R.ok().put("goodsAreaFeature", goodsAreaFeature);
    }

    /**
     * 保存
     */
    @PostMapping("/add")
    //@RequiresPermissions("areafeature:goodsareafeature:save")
    public R save(@RequestBody GoodsAreaFeatureDTO dto){
		goodsAreaFeatureService.add(dto);
        return R.ok();
    }

    /**
     * 修改顺序值
     */
    @PostMapping("/updateOrderIndex")
    //@RequiresPermissions("areafeature:goodsareafeature:update")
    public R update(@RequestBody GoodsAreaFeatureDTO dto){
		goodsAreaFeatureService.updateOrderIndex(dto);

        return R.ok();
    }

    /**
     * 删除
     */
    @DeleteMapping("/delete")
    //@RequiresPermissions("areafeature:goodsareafeature:delete")
    public R delete(@RequestBody Long[] ids){
		goodsAreaFeatureService.removeByIds(Arrays.asList(ids));
        return R.ok();
    }

}
